function sendReq(url,para,succ,fail){
	var dom = $(html).appendTo(document.body);
	$.ajax({
		type : "post",
		url : url,
		dataType : "json",
		data : para,
		error : function(msg) {
			dom.remove();
			if(typeof fail == "function"){
				fail(msg);
			}
		},
		success : function(data) {
			dom.remove();
			if(typeof succ == "function")
			succ(data);
		}
	});
}


var html = '<article class="loaders_box">\
	<div class="bg_box"></div>\
	<div class="iframe_box">\
		<article class="loaders_inner">\
			<div class="loaders_scale">\
				<div class="loader-inner line-scale">\
			      <div></div>\
			      <div></div>\
			      <div></div>\
			      <div></div>\
			      <div></div>\
			    </div>\
		    </div>\
	   		<p>加载中</p>\
	  	</article>\
	</div>\
	</article>';
/**
 * 发送跨域请求
 * @param url
 * @param para
 */
function sendAcrossReq(url,para){
	$.ajax({
		type : "post",
		url : url,
		dataType : "jsonp",
		data : para
	});
}

function onError(){
	
	
}
/**
 * 参数是一个回调方法，是获取位置成功后的回调
 * 方法会传入两个参数(经度，纬度)
 * @param callback
 */
function getLocation(callback){
  var options={
      enableHighAccuracy:true, 
      maximumAge:1000
  }
  if(navigator.geolocation){
      //浏览器支持geolocation
      navigator.geolocation.getCurrentPosition(function(position){
      	var longitude =position.coords.longitude;//经度
        var latitude = position.coords.latitude;//纬度
         if(typeof callback == "function"){
        	 callback(longitude,latitude);
         }
      },onError,options);
  }else{
      //浏览器不支持geolocation
  }
}
function hit_box_two(hint_title1,integral_number,hint_title2,btn_class1,btn_class2,hint_btn_title1,hint_btn_title2,okfunc,cancelfunc){
	var $hit_box_two='<article class="take_box total_box">\
	<div class="bg_box"></div>\
	<div class="iframe_box">\
		<div class="alert_box">\
			<p class="p_title">\
			'+hint_title1+'\
			<span class="special_color">'+integral_number+'</span>\
			'+hint_title2+'</p>\
			<div class="btn_all">\
				<a class="pass_btn '+btn_class1+'">'+hint_btn_title1+'</a>\
				<a class="close_btn '+btn_class2+'">'+hint_btn_title2+'</a>\
			</div>\
		</div>\
	</div>\
</article>';
$('.total_box').remove();
$('body').prepend($hit_box_two);
$('.close_btn').click(function(){//关闭按钮
	$('.total_box').remove();
	if(typeof cancelfunc == "function"){
		cancelfunc();
	}
});	
$(".pass_btn").click(function(){//确定按钮
	$('.total_box').remove();
	if(typeof okfunc == "function"){
		okfunc();
	}
	
});
}
function hit_box_one(hint_title1,prize_name,hint_title2,hint_btn_title,btn_class,func){
	var $hit_box_one='<article class="lottery_box total_box">\
		<div class="bg_box"></div>\
		<div class="iframe_box">\
			<div class="alert_box">\
				<p class="p_title">'+hint_title1+'<br/>\
				<span class="special_color">'+prize_name+'</span><br/>\
				<span style="font-size: 12px;">'+hint_title2+'</span></p>\
				<div class="btn_all">\
					<a class="fill_btn '+btn_class+'">'+hint_btn_title+'</a>\
				</div>\
			</div>\
		</div>\
	</article>';
	$('.total_box').remove();
	$('body').prepend($hit_box_one);

	$('.fill_btn').click(function(){//关闭按钮
		$('.total_box').remove();
		if(typeof func == "function"){
			func();
		}
	});	
	}

function hit_box_three(title,btn_class1,btn_class2,hint_btn_title1,hint_btn_title2,okfunc,cancelfunc){
	var $hit_box_one='<article class="lottery_box total_box">\
		<div class="bg_box"></div>\
		<div class="iframe_box">\
			<div class="alert_box" style="text-align:center;">\
				<p class="p_title" style="line-height: inherit">'+title+'<br/>\
					<textarea placeholder = "请输入15字评价信息哦" style="resize:none;width:75%;height:100px;"></textarea>\
					<div class="btn_all">\
							<a class="pass_btn '+btn_class1+'">'+hint_btn_title1+'</a>\
							<a class="close_btn '+btn_class2+'">'+hint_btn_title2+'</a>\
					</div>\
			</div>\
		</div>\
	</article>';
	$('.total_box').remove();
	$('body').prepend($hit_box_one);
	
	$('.close_btn').click(function(){//关闭按钮
		$('.total_box').remove();
		if(typeof cancelfunc == "function"){
			cancelfunc();
		}
	});	
	$(".pass_btn").click(function(){//确定按钮
		var text = $('.total_box textarea').val();
		$('.total_box').remove();
		if(typeof okfunc == "function"){
			okfunc(text);
		}
		
	});
	}

(function(){
	var checkFunc = {
			"name" : function(val, dom) {
				if (!val || val.length == 0) {
					dom.text = "姓名不能为空";
					dom.status = false;
					return false;
				}
				if(!/^[\u4e00-\u9fa5]+$/g.test(val)){
					dom.text = "姓名只能是中文";
					dom.status = false;
					return false;
				}
				if(val.length > 6){
					dom.text = "姓名太长";
					dom.status = false;
					return false;
				}
				dom.status = true;
			},
			"tel" : function(val, dom) {
				if (!val || val.length == 0) {
					dom.text = "手机号码不能为空";
					dom.status = false;
					return false;
				}
				if (!(/^1[3|4|5|7|8]\d{9}$/.test(val))) {
					dom.text = "手机号码格式有误";
					dom.status = false;
					return false;
				}
				dom.status = true;
			},
			"province" : function(val, dom) {
//		 		if (val == "省份") {


//		 			dom.text("省份不能为空");


//		 			return false;


//		 		}


				dom.status = true;
			},
			"city" : function(val, dom) {
//		 		if (val == "地级市") {


//		 			dom.text("城市不能为空");


//		 			return false;


//		 		}


				dom.status = true;
			},
			"country" : function(val, dom) {
//		 		if (val == "市、县级市") {


//		 			dom.text("区不能为空");


//		 			return false;


//		 		}


				dom.status = true;
			},
			"address" : function(val,dom) {
				
		 		if (!val || val.length == 0) {
		 			dom.text = "详细地址不能为空";
		 			dom.status = false;
		 			return false;
		 		}
		 		if(val.length >50){
		 			dom.text = "您的地址不能超过50个字符！";
		 			dom.status = false;
		 			return false;
		 		}
		 		dom.status = true;
			}
		}
	
	/**
	 * {
			success: submit,
			fail : function(msg){
				$(".from_hit_text").text(msg);
				}
		}
	 */
	$.fn.valid = function(opt){
		var sucFunc = opt["success"]||function(){};
		var failFunc = opt["fail"]||function(){};
		var self = this,len = self.length;
		var result = {status:true};
		var vals = {};
		for (var i = 0; i < len; i++) {
				var dom = self[i];
				var name = dom.getAttribute("name");
				if(!name) continue;
				var tagName = dom.tagName;
				var val = dom.value;
				vals[name] = val;
				if(typeof checkFunc[name] == "function"){
					checkFunc[name](val,result);
					if(result.status == false){
						failFunc(result.text);
						return;
					}
				}
		}
		sucFunc(vals);
	}
})();